HTML如何使一个层<div>在浏览器中始终居中?

来源:百度知道 编辑:UC知道 时间:2024/06/14 06:05:59
HTML如何使一个层<div>在浏览器中始终居中?

<div style="magin:0 auto; width=600px;"></div>

记住,页面得加上
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

超简单!
body{margin:0px; padding:0px; font-size:12px;}
#box{
width:200px;
height:200px;
position:absolute;
top:50%;
left:50%;
margin:-100px 0px 0px -100px;
background:#FFCC99;
line-height:200px;
text-align:center;
}

<div id="box">this is a box</div>

先给DIV的宽度,再设置左右自动对其即可

<div style"magin-left:auto;magin-right:auto;"></div>

<div align="center"></div>